package com.demo.mybatis.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.mi.rule.db.entity.MiEntity;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * 关联表（角色-菜单） 实体
 */
@Data
@TableName("sys_link_role_menu")
public class SysLinkRoleMenu extends Model<SysLinkRoleMenu> implements MiEntity {
    private static final long serialVersionUID = 1L;

    @TableId("role_id")
    private String roleId;

    @TableId("role_code")
    private String roleCode;

    @TableField("menu_ids")
    private String menuIds;


    /**
     * 返回菜单ID Set数组
     */
    public Set<String> getMenuIdSet() {
        HashSet<String> objects = new HashSet<>();
        if (StringUtils.isBlank(this.menuIds)) {
            return objects;
        }
        String[] split = this.menuIds.split(",");
        objects.addAll(Arrays.asList(split));
        return objects;
    }


}
